home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 1 / CU Amiga Magazine CD-ROM Special Edition (1995)(EMAP Images)(GB)[Issue 1995-11].iso / Aminet / text / tex / EVPaths140.lha / TeXWhereIs.c < prev    next >
C/C++ Source or Header  |  1995-05-05  |  3KB  |  100 lines

  1. /*
  2.  * TeXWhereIs.c - a simple file to show how evpaths.lib routines work.
  3.  *
  4.  * Copyright © 1994,1995 by Giuseppe Ghibò
  5.  *
  6.  * Version 1.1 - 5 May 1995
  7.  *
  8.  * -----------------------------------------------------------------------
  9.  * 
  10.  * Compile with:
  11.  *
  12.  *    SC OPT LINK NOSTKCHK LIB EVPaths.lib TeXWhereIs
  13.  * or
  14.  *    SC OPT LINK NOSTKCHK LIB EVPaths_no.lib TeXWhereIs
  15.  *
  16.  */
  17.  
  18. #include <stdio.h>
  19. #include <stdlib.h>
  20. #include "evpaths.h"
  21.  
  22. #define BUFLEN 256
  23. #define EVPBUF 8192L
  24.  
  25. char *default_path = ".,TeX:inputs,TeX:texinputs";
  26.  
  27. //char *default_path[] = { ".",
  28. //              "TeX:inputs",
  29. //              "TeX:texinputs",
  30. //              NULL };
  31.  
  32. void main(int argc, char **argv)
  33. {
  34.     struct EnvVarPath *var;
  35.     char buf[BUFLEN], *s;
  36.     FILE *fh;
  37.  
  38.     if (argc < 2)
  39.     {
  40.         fprintf(stderr,"TeXWhereIs v1.0 - © 1994 by Giuseppe Ghibò\n");
  41.         fprintf(stderr,"Usage:\n");
  42.         fprintf(stderr,"\tTeXWhereIs ENVVAR filename [-p]\n");
  43.         fprintf(stderr,"Example:\n");
  44.         fprintf(stderr,"\tTeXWhereIs MFINPUTS cmr10.mf\n");
  45.         fprintf(stderr,"Search the file `cmr10.mf' in the path specified by the environment\n");
  46.         fprintf(stderr,"variable `MFINPUTS' and then show where it is located. If the flag `-p'\n");
  47.         fprintf(stderr,"also specified then TeXWhereIs shows also the expanded entries of the\n");
  48.         fprintf(stderr,"specified environment variable.\n");
  49.         exit(1);
  50.     }
  51.  
  52. /* argv[1] = ENV VAR NAME, argv[2] = FILE NAME */
  53.  
  54.     var = Alloc_EnvVarPath(argv[1], EVPBUF);
  55.  
  56. /* note that Init_EnvVarPath() must be executed only once for each env var, unless
  57.    we call Free_EnvVarPath().
  58.    Here follow some alternatives for Init_EnvVarPath().
  59. */
  60.  
  61. //    Init_EnvVarPath(var, NULL, NULL);
  62. //    Init_EnvVarPath(var, default_path, ENVPATH_DEFARR);
  63. //    Init_EnvVarPath(var, default_path, ENVPATH_DEFSTR);
  64. //    Init_EnvVarPath(var, default_path, ENVPATH_DEFSTR | ENVPATH_APPEND_PATH );
  65.  
  66.     Init_EnvVarPath(var, default_path, ENVPATH_DEFSTR | ENVPATH_APPEND_PATH | ENVPATH_CURRENTDIR_FIRST);
  67.  
  68.     if (argv[3][0] == '-' && argv[3][1] == 'p')
  69.     {
  70.         int i = 0;
  71.         printf("The environment variable: %s has length %ld\n",argv[1],GetVarLength(argv[1]));
  72.         
  73.         while (var->storage.strings[i] != NULL)
  74.             printf("%d -> `%s'\n", i, var->storage.strings[i++]);
  75.  
  76.     }
  77.  
  78.     if (s = EVP_FileSearch(argv[2], var, buf, 256))
  79.         printf("File found: `%s'\n",s);
  80.         else
  81.         printf("No file found.\n");
  82.  
  83. /*
  84.     if (fh = EVP_fopen(argv[2],var,buf,256,"r"))
  85.     {
  86.         char p, q;
  87.  
  88.         printf("File found: `%s'\n",buf);
  89.         p = getc(fh);
  90.         q = getc(fh);
  91.  
  92.         printf("First two char: '%c%c'\n",p,q);
  93.     }
  94.     else
  95.         printf("No file found.\n");
  96. */
  97.  
  98.     Free_EnvVarPath(var); /* don't forget this!!! */
  99. }
  100.